import string

#headingDict = {}

class ircstuff:
    pass

#1   ,2    , 3         , 4           ,  5          ,  6     ,  7     , 8   ,  9  ,  10   ,  11   ,  12       ,  13
#type, lots, currency  , dateopen    ,  dateclose  ,  open  , close  ,high , low , pips  , Dollar, pipstotal ,dollarTotal


headingDict = {
1 : '''{|cellspacing="0" border="1" style="background:#eeeeee;" class="pair_2"''',
2 : "!Nr.",
3 : "!Type",
4 : "!Lots",
5 : "!Ticker",
6 : "!DateOpen",
7 : "!DateClosed",
8 : "!Open",
9 : "!Close",
10 : "!High",
11 : "!Pip drawdown nominal",
12 : "!Nominal movement",
13 : "!Dollar",
14 : "!PipsTotal",
15 : "!DollarTotal" ,
16 : "|-"
}

class WikiaHeader:
    def __init__(self, irclibobj):
        self.tickerDict = {}


    def GenerateHeader(self):
        file = open("wikia.txt",'w')
        tradenr = headingDict.items()
        #hosts.sort()
        for iter,count in tradenr:
            x = headingDict[iter]
            x = x + '\r\n'
            file.write(x)
#            templist = self.tickerDict[iter]
            #print templist
           # print host, ":", count
        file.close()


    def formatZulu_File(self):
        tempstring = ''
        try:
            file = open("zulutemp.txt")
            filewrite = open("zuluformat.txt",'w')
        except:
            print ("file not opening")
            sys.exit(1)
        for x in range(50000000):
            line = file.readline()
            if line:
                pass
            else:
                file.close()
                filewrite.close()
                break
            if line:
                temp = string.strip(line)
                if temp == '': #if empty line not yet read, still busy with same dataset.
                    for x in range(13):
                        line = file.readline()  # will be buy or sell
                        line = string.strip(line)
                        tempstring = tempstring +  line + ','
                    tempstring = tempstring[:-1]
                    tempstring = tempstring + "\n"
#                    tempstring = tempstring + "\r\n"  #CHANGED THIS LINE
                    if "Pips" in tempstring:
                        filewrite.write(tempstring)
                    tempstring = ''
            else:
                file.close()
                filewrite.close()
                break


    def thefileread(self):
        try:
            file = open("zuluformat.txt")
        except:
            print ("file not opening")
            sys.exit(1)
        for x  in range(5000000):
#        while 1:
            line = file.readline()
            if line:
                mytemp = string.split(line,",")
                temp = mytemp[0]
                self.tickerDict[x] = mytemp
            else:
                break


